package com.vogue.supplymall.admin.business.domain.dao.impl;

import com.vogue.supplymall.admin.business.domain.dao.AdminDictDao;
import com.vogue.supplymall.admin.business.domain.mapper.AdminDictMapper;
import com.vogue.supplymall.admin.business.domain.model.AdminDict;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * The type Admin dict dao.
 *
 * @aouthor: zhangliang
 * @date: Create in 2018-05-07
 */
@Repository("adminDictDao")
public class AdminDictDaoImpl extends BaseDaoImpl<AdminDict, Long> implements AdminDictDao {
    @Resource
    private AdminDictMapper adminDictMapper;

    @Override
    public List<Map<String, Object>> findDict(Integer type, String keyword) {
        String sql = "select name,code,type from admin_dict where type = #{type}";
        Map<String, Object> para = new HashMap<>();
        para.put("type", type);
        if (StringUtils.isNotEmpty(keyword)) {
            sql = sql + " and name like CONCAT('%',#{keyword},'%') ";
            para.put("keyword", keyword);
        }
        return adminDictMapper.query0(sql, para);
    }
}
